%%
% note : this only works for a single type of data (selection).

sf=getmainselection();
a=getstructs('SAC3.NPH1');
t=getstructs('SAC3.tmid');
f = getstructs('filename');
r = getstructs('reclist');
ec = getstructs('E_C');
g1 = getstructs('G1');
fprintf(1, '\nSac3_summary_plot results, %s\n', datestr(now)); 
fprintf(1, 'Running Matlab version %s  on a %s computer\n', version, computer);
fprintf('\n  Filename \t   Records \t E_C\tG1\n');
for i = 1:length(f)
    fprintf(' %s\t %s\t %s\t %d\t\n', f{i}, r{i}, ec{i}, number_arg(g1{i}));
end;


fprintf(1, '\n\nRaw \n');
for i = 1:length(a{1})
    fprintf(1, '\n');
    for j = 1:length(a)
        fprintf(1, '%f\t', a{j}(i));
    end;
end;

fprintf(1, '\n\nNormalized:\n');
an = NaN*zeros(length(a), length(a{1}));

for j = 1:length(a)
    an(j,:) = a{j}/(mean(a{j}(2:4)));
end;
for i = 1:size(an, 1)
    fprintf(1, '\n');
    for j = 1:size(an, 2)
        fprintf(1, '%f\t', an(i,j));
    end;
end;
fprintf(1, '\n\n t\tmean\tStdDev\t(N = %d)\n', size(an,1));

mi=zeros(size(an, 2),1);
si = mi;


for i = 1:size(an,2)
    [mi(i), si(i)] = mean_var(an(:,i));
    fprintf(1, '%f\t%f\t%f\n', t{1}(i), mi(i), si(i));
end;

newfigure('SAC3_average', 'SAC3 Average');
plot_witherror(t{1}(1:end-1), mi(1:end-1), si(1:end-1), [2:4]);